package com.ynwt.service;

import com.github.sd4324530.fastweixin.api.MaterialAPI;
import com.github.sd4324530.fastweixin.api.enums.MaterialType;
import com.github.sd4324530.fastweixin.api.response.GetMaterialListResponse;
import com.github.sd4324530.fastweixin.api.response.GetMaterialTotalCountResponse;
import com.ynwt.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by huangying on 2017/5/23.
 */
@Service
public class MaterialServiceImpl implements MaterialService {

    public void batchGetImage() {

        GetMaterialTotalCountResponse countResponse = materialAPI.countMaterial();
        int total = countResponse.getImage();

        for (int i = 0; i < total; i += 20) {
            int count = i + 20 <= total ? 20 : total - i;
            GetMaterialListResponse response = materialAPI.batchGetMaterial(MaterialType.IMAGE, i, count);
            List list = response.getItems();
            System.out.println(JsonUtil.toJsonStr(list));
        }

    }

    @Autowired
    private MaterialAPI materialAPI;
}
